<template>
	<view class="new_page">
		<view class="main">
			<view class="order_detail">
				<view class="title">
					<template v-if="info.orderStatus=='A'">
						<image src="https://hetp.hephp.cn/static/images/yzf.png" mode="widthFix"></image>
						<text>
							已支付
						</text>
					</template>
					<template v-if="info.orderStatus=='V'">
						<image src="https://hetp.hephp.cn/static/images/ywc.png" mode="widthFix"></image>
						<text>
							已核销
						</text>
					</template>
					<template v-if="info.orderStatus=='P'">
						<image src="https://hetp.hephp.cn/static/images/sqtk.png" mode="widthFix"></image>
						<text>
							申请退款
						</text>
					</template>
					<template v-if="info.orderStatus=='R'">
						<image src="https://hetp.hephp.cn/static/images/ytk.png" mode="widthFix"></image>
						<text>
							已退款
						</text>
					</template>
					<template v-if="info.orderStatus==''">
						<image src="https://hetp.hephp.cn/static/images/home_tk.png" mode="widthFix"></image>
						<text>
							待支付
						</text>
					</template>
					
					<!-- <template>
						<text v-if="info.orderStatus=='A'">
							已支付
						</text>
						<text v-else-if="info.orderStatus=='V'">
							已核销
						</text>
						<text v-else-if="info.orderStatus=='P'">
							申请退款
						</text>
						<text v-else-if="info.orderStatus=='R'">
							已退款
						</text>
						<text v-else>
							待支付
						</text>
					</template> -->

				</view>

				<view class="goods_wrap">
					<view class="left">
						<image :src="info.images" mode="widthFix"></image>
					</view>
					<view class="right">
						<view class="goods_name two-row">
							<text>【{{info.eventName}}】</text>
						</view>
						<view class="goods_info">
							<text>¥199</text>
							<text style="font-size: 25rpx;color: #3D3D3D;">x1</text>
						</view>
						<view class="goods_price">
							<text>总计：¥199</text>
						</view>
					</view>
				</view>

				<!-- 退款面板 -->
				<view class="tuikuan" v-if="info.orderStatus=='P'">
					<uni-section title="退款" type="line" padding>
						<uni-steps :options="stepList" active-color="#007AFF" :active="active" direction="column" />
					</uni-section>
					<view class="btn_wrap">
						<view class="cancel_btn btn" @click="handleTK(0)">
							<text>拒绝</text>
						</view>
						<view class="ty_btn btn" @click="handleTK(1)">
							<text>同意</text>
						</view>
					</view>
				</view>

				<view class="goods_order">
					<view class="one">
						<view class="text">
							<text>订单号</text>
						</view>
						<view class="rt">{{info.orderId}}</view>
					</view>
					<view class="one">
						<view class="text">
							<text>用户昵称/id</text>
						</view>
						<view class="rt">{{info.nickName}}</view>
					</view>
					<view class="one">
						<view class="text">
							<text>手机号</text>
						</view>
						<view class="rt">{{info.phoneNumber}}</view>
					</view>
					<view class="one">
						<view class="text">
							<text>活动名称</text>
						</view>
						<view class="rt">{{info.eventName}}</view>
					</view>
					<view class="one">
						<view class="text">
							<text>店铺名称</text>
						</view>
						<view class="rt">{{info.orderRehabCenterName}}</view>
					</view>
					<view class="one">
						<view class="text">
							<text>下单时间</text>
						</view>
						<view class="rt">{{info.orderDateTime}}</view>
					</view>
					<!-- 已核销 -->
					<view class="one" v-if="info.orderStatus=='V'">
						<view class="text">
							<text>核销时间</text>
						</view>
						<view class="rt">{{info.VerifiedDatetime}}</view>
					</view>
					<!-- 退款原因 -->
					<view class="one" v-if="info.orderStatus=='P'||info.orderStatus=='R'">
						<view class="text">
							<text>退款原因</text>
						</view>
						<view class="rt">--</view>
					</view>
					<!-- 退款时间 -->
					<view class="one" v-if="info.orderStatus=='P'||info.orderStatus=='R'">
						<view class="text">
							<text>退款时间</text>
						</view>
						<view class="rt">{{info.RefundRequestDatetime||'--'}}</view>
					</view>
				</view>

			</view>
		</view>
	</view>
</template>

<script>
	import {
		gethexiaodetail,
		orderTuiKuan
	} from '@/request/api.js'
	import {
		toast,
		useRouter
	} from '@/request/utils.js'
	export default {
		data() {
			return {
				id: '',
				info: {
					orderId: '',
					orderDateTime: '',
					eventName: "",
					totalFee: '',
					orderStatus: '',
					VerifiedDatetime: ''
				},
				active: 0,
				stepList: [{
					title: '待商家处理',
					desc: '该笔钱会自动退回给顾客'
				}, {
					title: '顾客申请全部退款',
					desc: ''
				}],
			}
		},
		onLoad(openid) {
			this.id = openid.id
			this.gethexiaodetail(openid.id)
		},
		methods: {
			async gethexiaodetail(nums) {
				let res = await gethexiaodetail({
					id: nums
				});
				if (res.code == 200) {
					console.log(res.data)
					this.info = res.data
				} else {
					toast(res.message)
					this.goToNoLoginPage('/pages/index/index', 'navigateTo');
				}
			},
			handleTK(index){
				if(index){
					uni.showModal({
						title: '提示！',
						content: '是否同意退款',
						cancelText: '取消',
						success: async (res)=> {
							if (res.confirm) {
								let res = await orderTuiKuan({status:'R',id:this.info.orderId});
								
								this.gethexiaodetail(this.id);
							}
								
							if(res.cancel){
								
							}
						}
					})
				}else{
					uni.showModal({
						title: '提示！',
						content: '是否拒绝退款',
						cancelText: '取消',
						success: (res)=> {
							if (res.confirm) {
								
							}
								
							if(res.cancel){
								
							}
						}
					})
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.order_detail {
		width: 699.28rpx;
		margin: auto;
		padding-bottom: 50rpx;

		.title {
			padding: 40rpx 0;
			display: flex;
			justify-content: flex-start;
			align-items: center;
			font-size: 36rpx;

			image {
				width: 60rpx;
				margin-right: 20rpx;
			}
		}

		.goods_wrap {
			background-color: #fff;
			border-radius: 10rpx;
			padding: 30rpx;
			display: flex;
			justify-content: flex-start;
			align-items: flex-start;

			.left {
				image {
					width: 140rpx;
					margin-right: 10rpx;
				}
			}

			.right {
				.goods_name {
					font-size: 29rpx;
				}
				.goods_info {
					font-size: 29rpx;
					padding: 20rpx 0;
					display: flex;
					justify-content: space-between;
					align-items: center;
					border-bottom: 1px solid $line-grey;
				}

				.goods_price {
					display: flex;
					justify-content: flex-end;
					font-weight: bold;
					margin-top: 10rpx;
					font-size: 33rpx;
				}
			}

		}
		
		.tuikuan {
			margin-top: 40rpx;
			background-color: #fff;
			border-radius: 10rpx;
			padding: 30rpx;
			.btn_wrap {
				display: flex;
				justify-content: flex-end;
				align-items: center;
				.btn {
					padding: 6rpx 18rpx;
					border-radius: 6rpx;
					margin-top: 20rpx;
					&.cancel_btn {
						background-color: #dadada;
					}
					&.ty_btn {
						background-color: #4570ee;
						color: #fff;
						margin-left: 20rpx;
					}
				}
			}
		}
		
		.goods_order {
			margin-top: 40rpx;
			background-color: #fff;
			border-radius: 10rpx;
			padding: 30rpx;

			.one {
				display: flex;
				justify-content: space-between;
				align-items: center;
				.text {
					font-size: 25rpx;
				}
				.rt {
					font-size: 22rpx;
					color: #464648;
					text-align: right;
					margin-left: 30rpx;
					flex: 1;
					max-width: 70%;
					padding: 25rpx 0;
					border-bottom: 1px solid #F2F2F2;
					word-break: break-all;
				}
			}
		}
	}
</style>